//
//  DeviceRenameViewController.m
//  AlinkDemo
//
//  Created by Vincent on 2017/10/28.
//  Copyright © 2017年 aliyun. All rights reserved.
//

#import "DeviceRenameViewController.h"

@interface DeviceRenameViewController ()

@property (weak, nonatomic) IBOutlet UIButton *confirmButton;
@property (weak, nonatomic) IBOutlet UITextField *textFiled;
@property (weak, nonatomic) IBOutlet UIButton *cancelButton;
- (IBAction)buttonClick:(id)sender;
@end

@implementation DeviceRenameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9];
    self.confirmButton.layer.cornerRadius =5.0;
    self.cancelButton.layer.cornerRadius =5.0;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMessageResult:) name:equesOnMessageResultNotification object:nil];

}

- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];


}


#pragma mark 收到的消息
- (void)onMessageResult:(NSNotification *)notification{
    NSDictionary *messageResult = [notification object];

    NSString *method = messageResult[@"method"];
    NSInteger code = [messageResult[@"code"] integerValue];
    if ([method isEqualToString:@"setnick"]) {

        if (code==4000) {
            [SVProgressHUD showSuccessWithStatus:@"修改成功！"];

            [YKBusinessFramework equesGetDeviceList];
            
            [self.mz_formSheetPresentingPresentationController dismissViewControllerAnimated:YES completion:nil];

        }else{
            [SVProgressHUD showErrorWithStatus:@"修改失败！"];
        }

    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)buttonClick:(UIButton *)sender {
    if (sender.tag==0) {
        if (self.textFiled.text.length>0) {
            [YKBusinessFramework equesSetDeviceNickWithBid:self.bid Nick:self.textFiled.text];

        }
    }else{
        [self.mz_formSheetPresentingPresentationController dismissViewControllerAnimated:YES completion:nil];
    }
}
@end
